knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE, fig.height = 4, fig.width = 7)
library(terra)
library(oharac)
library(tidyverse)
library(here)
source(here('common_fxns.R'))With impact maps generated for all stressors, means calculated both species and FE, we can add the impact layers to generate a comprehensive cumulative human impact map. This script aggregates by stressor group: fishing-related, land-based, ocean-based, and climate.
See scripts 2, 3a, and 3b for vulnerability mapping scripts, and scripts 4a-4d for impact calculation scripts.
Sum impacts across all stressor/vulnerability combos, by stressor group.
str_gp_df <- read_csv(here('_raw/stressor_vulnerability_lookup.csv'))imp1_fs <- list.files(here_anx('_output/impact_maps/impact_maps_species'),
pattern = 'mean',
full.names = TRUE)
imp1_stack <- rast(imp1_fs) %>%
setNames(str_remove_all(basename(imp1_fs), '.+_spp_|_x_.+|_mean.tif'))
ocean_a_rast <- rast(here('_spatial/ocean_area_mol.tif'))
spp_outfile_stem <- here('_output/cumulative_impact_maps/species_group_chi_%s.tif')
str_gps <- str_gp_df$stressor_group %>% unique()
for(str_gp in str_gps) {
### str_gp <- str_gps[1]
spp_outfile <- sprintf(spp_outfile_stem, str_gp)
if(!file.exists(spp_outfile)) {
str_vec <- str_gp_df %>%
filter(stressor_group == str_gp) %>%
.$stressor
gp_stack <- imp1_stack[[str_vec]]
### Calculate cumulative impacts for this group
gp_chi_spp_raw <- sum(gp_stack, na.rm = TRUE)
gp_chi_species <- gp_chi_spp_raw %>%
mask(ocean_a_rast) %>%
setNames(sprintf('%s_chi_spp', str_gp))
writeRaster(gp_chi_species, spp_outfile,
overwrite = TRUE)
}
}for(s in str_gps) {
### s <- str_gps[1]
f <- sprintf(spp_outfile_stem, s)
r <- rast(f)
plot(log10(r), col = hcl.colors(50),
main = paste0('Log_10(', s, ' stressors), species'),
axes = FALSE)
}Sum impacts across all stressor/vulnerability combos.
imp2_fs <- list.files(here_anx('_output/impact_maps/impact_maps_funct_entity'),
pattern = 'mean',
full.names = TRUE)
imp2_stack <- rast(imp2_fs) %>%
setNames(str_remove_all(basename(imp2_fs), '.+_fe_|_x_.+|_mean.tif'))
fe_outfile_stem <- here('_output/cumulative_impact_maps/funct_entity_group_chi_%s.tif')
str_gps <- str_gp_df$stressor_group %>% unique()
for(str_gp in str_gps) {
### str_gp <- str_gps[1]
fe_outfile <- sprintf(fe_outfile_stem, str_gp)
if(!file.exists(fe_outfile)) {
str_vec <- str_gp_df %>%
filter(stressor_group == str_gp) %>%
.$stressor
gp_stack <- imp2_stack[[str_detect(names(imp2_stack), smash2or(str_vec))]]
### Calculate cumulative impacts for this group
gp_chi_fe_raw <- sum(gp_stack, na.rm = TRUE)
gp_chi_fe <- gp_chi_fe_raw %>%
mask(ocean_a_rast) %>%
setNames(sprintf('%s_chi_fe', str_gp))
writeRaster(gp_chi_fe, fe_outfile,
overwrite = TRUE)
}
}for(s in str_gps) {
### s <- str_gps[1]
f <- sprintf(fe_outfile_stem, s)
r <- rast(f)
plot(log10(r), col = hcl.colors(50),
main = paste0('Log_10(', s, ' stressors), FE'),
axes = FALSE)
}Difference in CHI calculated from FE vulnerability relative to species vulnerability (using only spp included in functional entities): \[\frac{CHI_{FE} - CHI_{spp}}{CHI_{spp}} \times 100\%\]
for(s in str_gps) {
### s <- str_gps[1]
f1 <- sprintf(fe_outfile_stem, s)
r1 <- rast(f1)
f2 <- sprintf(spp_outfile_stem, s)
r2 <- rast(f2)
r <- (r1 - r2) / r2
plot(r, col = hcl.colors(50),
main = paste0('Difference: FE vs species ', s, ' stressors'),
axes = FALSE)
}